package com.aring.deals.actions;

import java.lang.reflect.Type;

import org.apache.struts2.ServletActionContext;

import com.aring.constant.CommConstant;
import com.aring.deals.bean.JsonBean;
import com.aring.deals.listener.OptionListener;
import com.aring.deals.option.UserOption;
import com.aring.deals.tool.Common;
import com.google.gson.reflect.TypeToken;
import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings("serial")
public class CheckWithdrawPassAction extends BasicAction{

	@Override
	public String execute() throws Exception {
		setOut(ServletActionContext.getResponse().getWriter());
		Integer id = (Integer) ActionContext.getContext().getSession().get(CommConstant.SESSION_USER_ID);
	    if(id==null) handleNotLogin();
	    else {
	      setId(id);
	      UserOption.checkWithdrawPass(getId(), new OptionListener<Integer>() {
			
			@Override
			public void onSuccess(Integer resultCode) {
				outResult(resultCode);
			}
			
			@Override
			public void onFailure(int resultCode) {
				outResult(resultCode);
			}
		});
		}
		
		return null;
	}
	
	
private	void outResult(int resultCode){
	JsonBean<String> json = new JsonBean<String>();
	json.setResultCode(resultCode);
	Type type = new TypeToken<JsonBean<String>>() {}.getType();
	getOut().write(Common.packageJson(json, type));
	getOut().flush();
	getOut().close();
}
	
	
}
